﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Diagnostics;
using System.IO;

namespace FFXIRC_CLIENT
{

    static class Program
    {
        public static bool parseChatLog = false;
        public static bool showMOTD = true;
        public static ManualResetEvent identified = new ManualResetEvent(false);
        public static ManualResetEvent parseChatLogEvent = new ManualResetEvent(false);
        public static ManualResetEvent isConnectedToIRC = new ManualResetEvent(false);

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(String[] args)
        {
            FFXI.FFACE.Main.InitFFACE();
            Thread.Sleep(100);
            GetProcess();
#if DEBUG
            Console.WriteLine("POL ID:" + FFXI.Windower.PolID);
            Console.WriteLine("Player: " + FFXI.FFACE.Player.Name());
#endif
            IrcClient.setupClient();

            if (args.Length >= 2)
            {
                IrcClient.f2i.parseCommand(new String[] { "LOADFILE", args[1] });
            }
            else
            {
                IrcClient.f2i.parseCommand(new String[] { "LOADFILE", "FFXIRC.ini" });
            }

        }
        public static void GetProcess()
        {
            try
            {
                Process[] ProcessList = Process.GetProcesses();

                for (int i = 0; i < ProcessList.Length; i++)
                {
                    string ProcessName = ProcessList[i].ProcessName;
#if DEBUG
                    Console.WriteLine("Process name: " + ProcessName + " PID: " + ProcessList[i].Id);
#endif
                    if (ProcessName == "pol")
                    {
                        if (ProcessList[i].MainWindowTitle.Contains(FFXI.FFACE.Player.Name()))
                        {
                            string PolID = "" + ProcessList[i].Id;
                            FFXI.Windower.PolID = PolID;
                        }
                    }
                }
            }
            catch { }
        }
    }
}
